import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/box/model/models.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/my/view/album_hint.dart';
import 'package:nft_shop/my/view/my_editor_works_bottom.dart';
import 'package:nft_shop/net/dio_api.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/util/other_utils.dart';
import 'package:nft_shop/util/select_image_utils.dart';
import 'package:nft_shop/util/textfield_inputnum_utils.dart';
import 'package:nft_shop/widgets/image.dart';
import 'package:nft_shop/widgets/load_image.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/my_button.dart';
import 'package:nft_shop/widgets/my_scroll_view.dart';

class MyWorksCreationPage extends StatefulWidget {
  MyGoodsSpecialModel? model;

  MyWorksCreationPage({Key? key, this.model}) : super(key: key);

  @override
  _MyWorksCreationPageState createState() => _MyWorksCreationPageState();
}

class _MyWorksCreationPageState extends State<MyWorksCreationPage> {
  String textItem1 = "藏品";
  String textItem2 = "";
  String textItem3 = "";
  String textItem4 = "";

  //藏品
  String urlStr1 = "";
  String urlStr3D = "";

  //单个作品 //多个作品
  bool isSingle = true;

  List<SpecialTypeModel> typeList = [];
  List<AlbumListModel> albumList = [];

  String ID = "";
  String typeID = "";
  String albumID = "";

  //盲盒
  String urlStr2 = "";

  //盲盒首图
  String urlStr3 = "";

  //作品总数
  int allCount = 0;

  //作品描述
  List<WorksBoxModel> worksList = [];

  final TextEditingController _controller1 = TextEditingController();
  final FocusNode _nodeText1 = FocusNode();
  final TextEditingController _controller2 = TextEditingController();
  final FocusNode _nodeText2 = FocusNode();
  final TextEditingController _controller3 = TextEditingController();
  final FocusNode _nodeText3 = FocusNode();
  final TextEditingController _controller4 = TextEditingController();
  final FocusNode _nodeText4 = FocusNode();
  final TextEditingController _controller5 = TextEditingController();
  final FocusNode _nodeText5 = FocusNode();
  final TextEditingController _controller6 = TextEditingController();
  final FocusNode _nodeText6 = FocusNode();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    if (widget.model != null) {
      textItem1 = widget.model!.type == 1 ? "藏品" : "盲盒";
      ID = widget.model!.specialId ?? "";
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    EasyLoading.dismiss();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "创建作品",
      ),
      body: MyScrollView(
        children: textItem1 == "藏品" ? getObject() : getBox(),
        bottomButton: Container(
          height: 40,
          margin: EdgeInsets.only(
              top: 5,
              left: 14,
              right: 14,
              bottom: 22 + ScreenUtil.getBottomBarH(context)),
          decoration: BoxDecoration(
            color: Global.kTheme.colorBackground3,
            borderRadius: BorderRadius.circular(4),
          ),
          child: MyButton(
            minHeight: 40,
            onPressed: () async {
              _nodeText1.unfocus();
              _nodeText2.unfocus();
              _nodeText3.unfocus();
              _nodeText4.unfocus();
              _nodeText5.unfocus();
              _nodeText6.unfocus();

              if (textItem1 == "藏品") {
                if (typeID.length == 0) {
                  EasyLoading.showToast("请选择您要铸造的作品类型");
                  return;
                }
                if (albumID.length == 0) {
                  EasyLoading.showToast("请选择所属专辑");
                  return;
                }

                if (_controller1.text.length == 0) {
                  EasyLoading.showToast("请输入作品标题");
                  return;
                }

                if (_controller2.text.length == 0 && isSingle == false) {
                  EasyLoading.showToast("请输入作品数量");
                  return;
                }

                if (_controller3.text.length == 0) {
                  EasyLoading.showToast("请输入您的作品灵感的由来");
                  return;
                }

                //3D
                if (typeID == "2") {
                  if (urlStr1.length == 0) {
                    EasyLoading.showToast("请上传封面图");
                    return;
                  }
                  if (urlStr3D.length == 0) {
                    EasyLoading.showToast("请上传3D文件");
                    return;
                  }
                } else {
                  if (urlStr1.length == 0) {
                    EasyLoading.showToast("请上传作品");
                    return;
                  }
                }

                EasyLoading.show(status: '加载中...');
                try {
                  await ServiceRepository.createSpecialCang(
                    ID: ID,
                    typeId: typeID,
                    albumId: albumID,
                    title: _controller1.text,
                    count: isSingle == true ? "1" : _controller2.text,
                    detail: _controller3.text,
                    // address: urlStr3D,
                    address: urlStr1,
                    thumb: urlStr1,
                  );
                  EasyLoading.showToast("创建成功,审核1-3个工作日给结果");
                  Get.back();
                } catch (s, e) {
                  EasyLoading.showToast(http.setError(e, e));
                }
              } else {
                if (typeID.length == 0) {
                  EasyLoading.showToast("请选择您要铸造的作品类型");
                  return;
                }
                if (_controller4.text.length == 0) {
                  EasyLoading.showToast("请输入作品专题名称(12个字符以内)");
                  return;
                }
                if (worksList.length == 0) {
                  EasyLoading.showToast("请添加作品描述");
                  return;
                }

                if (urlStr2.length == 0) {
                  EasyLoading.showToast("请添加细节展示");
                  return;
                }

                if (_controller6.text.length == 0) {
                  EasyLoading.showToast("请添加作品故事");
                  return;
                }
                List<String> objWorksList = [];
                for (var i = 0; i < worksList.length; i++) {
                  WorksBoxModel element = worksList[i];
                  if (element.title == null || element.title == "") {
                    print("标题-----${element.title ?? "空的"}");
                    EasyLoading.showToast("请输入盲盒作品名字");
                    return;
                  }
                  if (element.totalCount == null || element.totalCount == "") {
                    EasyLoading.showToast("请输入数量");
                    return;
                  }
                  if (element.basePrice == null || element.basePrice == "") {
                    EasyLoading.showToast("请输入价值多少钱");
                    return;
                  }
                  if (element.thumb == null || element.thumb == "") {
                    EasyLoading.showToast("请上传图片");
                    return;
                  }
                  objWorksList.add(JsonUtil.encodeObj(element).toString());
                }
                EasyLoading.show(status: '加载中...');
                try {
                  await ServiceRepository.createSpecialMang(
                      ID: ID,
                      typeId: typeID,
                      albumId: albumID,
                      title: _controller4.text,
                      count: allCount,
                      thumb: urlStr3,
                      detail: urlStr2,
                      story: _controller6.text,
                      blindBox: objWorksList.toString());
                  EasyLoading.showToast("创建成功,审核1-3个工作日给结果");
                  Get.back();
                } catch (s, e) {
                  EasyLoading.showToast(http.setError(e, e));
                }
              }
            },
            text: "提交审核",
            fontSize: 16,
            textColor: Colors.white,
            backgroundColor: Global.kTheme.colorBackground3,
          ),
        ),
      ),
    );
  }

  //藏品
  List<Widget> getObject() {
    return [
      selectTextItem(
          "作品形式",
          textItem1.length != 0 ? textItem1 : "请选择您要铸造的作品形式",
          textItem1.length != 0
              ? Global.kTheme.textPrimary6
              : Global.kTheme.textPrimary12, onPressed: () {
        if (widget.model != null) return;
        showModalBottomSheet<void>(
            context: context,

            /// 禁止拖动关闭
            enableDrag: false,

            /// 使用true则高度不受16分之9的最高限制
            isScrollControlled: true,
            backgroundColor: Colors.transparent,
            builder: (_) => MyEditorWorksBottom(
                  listName: [
                    "藏品",
                    "盲盒",
                  ],
                  onTap: (index) {
                    if (index == 0) {
                      setState(() {
                        textItem1 = "藏品";
                      });
                    } else if (index == 1) {
                      setState(() {
                        textItem1 = "盲盒";
                      });
                    }
                  },
                ));
      }),
      selectTextItem(
          "类型作品",
          textItem2.length != 0 ? textItem2 : "请选择您要铸造的作品类型",
          textItem2.length != 0
              ? Global.kTheme.textPrimary6
              : Global.kTheme.textPrimary12, onPressed: () async {
        if (typeList.length == 0) {
          try {
            EasyLoading.show(status: '加载中...');
            typeList = await ServiceRepository.goodsSpecialTypeList();
            EasyLoading.dismiss();

            List<String> nameList = [];
            typeList.forEach((element) {
              nameList.add(element.title ?? "");
            });
            print("数组个数---${nameList.length}");
            bottomDialog(nameList, (index) {
              print("选择11---${typeList[index].id}");
              setState(() {
                textItem2 = nameList[index];
                typeID = "${typeList[index].id}";
              });
            });
          } catch (e, s) {
            EasyLoading.showToast("加载失败");
          }
        } else {
          List<String> nameList = [];
          typeList.forEach((element) {
            nameList.add(element.title ?? "");
          });
          bottomDialog(nameList, (index) {
            setState(() {
              textItem2 = nameList[index];
              typeID = "${typeList[index].id}";
            });
          });
        }
      }),
      selectTextItem(
          "所属专辑",
          textItem3.length != 0 ? textItem3 : "请选择所属专辑",
          textItem3.length != 0
              ? Global.kTheme.textPrimary6
              : Global.kTheme.textPrimary12, onPressed: () async {
        if (albumList.length == 0) {
          try {
            EasyLoading.show(status: '加载中...');
            albumList = await ServiceRepository.specialAlbumList(
                page: 1, pageSize: 100, status: 2, type: 1);
            EasyLoading.dismiss();

            List<String> nameList = [];
            if (albumList.length == 0) {
              Utils.showElasticDialog<void>(
                context: context,
                barrierDismissible: false,
                builder: (BuildContext context) {
                  return AlbumHintDialog();
                },
              );
              return;
            }

            albumList.forEach((element) {
              nameList.add(element.specialAlbumTitile ?? "");
            });
            print("数组个数---${nameList.length}");
            bottomDialog(nameList, (index) {
              setState(() {
                textItem3 = nameList[index];
                textItem4 = (albumList[index].specialAlbumRate ?? "0.00") + "%";
                albumID = "${albumList[index].specialAlbumId}";
              });
            });
          } catch (e, s) {
            EasyLoading.showToast("加载失败");
          }
        } else {
          List<String> nameList = [];
          albumList.forEach((element) {
            nameList.add(element.specialAlbumTitile ?? "");
          });
          bottomDialog(nameList, (index) {
            setState(() {
              textItem3 = nameList[index];
              textItem4 = (albumList[index].specialAlbumRate ?? "0.00") + "%";
              albumID = "${albumList[index].specialAlbumId}";
            });
          });
        }
      }),
      selectTextItem(
        "版权金",
        textItem4.length != 0 ? textItem4 : "0.00%",
        Global.kTheme.textPrimary6,
      ),
      textFieldViewItem(
          left: "作品标题",
          controller: _controller1,
          focusNode: _nodeText1,
          hintText: "请输入(12个字符以内)"),
      optionViewItem(),
      if (isSingle == false)
        textFieldViewItem(
            left: "铸造份数",
            controller: _controller2,
            focusNode: _nodeText2,
            hintText: "请输入作品数量",
            keyboardType: TextInputType.numberWithOptions(decimal: false),
            maxNum: "10000"),
      describeView(_controller3, "作品描述"),
      typeID == "2" ? uploading3DView() : uploadingView(),
    ];
  }

  //盲盒
  List<Widget> getBox() {
    if (widget.model != null) {
      _controller4.text = widget.model!.title ?? "";
      textItem2 = widget.model!.specialTypeName ?? "";
      urlStr3 = widget.model!.thumb ?? "";
      urlStr2 = widget.model!.portrait ?? "";
    }

    return [
      selectTextItem(
          "作品形式",
          textItem1.length != 0 ? textItem1 : "请选择您要铸造的作品形式1",
          textItem1.length != 0
              ? Global.kTheme.textPrimary6
              : Global.kTheme.textPrimary12, onPressed: () {
        showModalBottomSheet<void>(
            context: context,

            /// 禁止拖动关闭
            enableDrag: false,

            /// 使用true则高度不受16分之9的最高限制
            isScrollControlled: true,
            backgroundColor: Colors.transparent,
            builder: (_) => MyEditorWorksBottom(
                  listName: [
                    "藏品",
                    "盲盒",
                  ],
                  onTap: (index) {
                    if (index == 0) {
                      setState(() {
                        textItem1 = "藏品";
                      });
                    } else if (index == 1) {
                      setState(() {
                        textItem1 = "盲盒";
                      });
                    }
                  },
                ));
      }),
      selectTextItem(
          "类型作品",
          textItem2.length != 0 ? textItem2 : "请选择您要铸造的作品类型",
          textItem2.length != 0
              ? Global.kTheme.textPrimary6
              : Global.kTheme.textPrimary12, onPressed: () async {
        if (typeList.length == 0) {
          try {
            EasyLoading.show(status: '加载中...');
            typeList = await ServiceRepository.goodsSpecialTypeList();
            EasyLoading.dismiss();

            List<String> nameList = [];
            typeList.forEach((element) {
              nameList.add(element.title ?? "");
            });
            print("数组个数---${nameList.length}");
            bottomDialog(nameList, (index) {
              //盲盒不能选择3D
              if (typeList[index].id == 2) {
                EasyLoading.showToast("盲盒不支持${nameList[index]}");
                return;
              }
              setState(() {
                textItem2 = nameList[index];
                typeID = "${typeList[index].id}";
              });
            });
          } catch (e, s) {
            EasyLoading.showToast("加载失败");
          }
        } else {
          List<String> nameList = [];
          typeList.forEach((element) {
            nameList.add(element.title ?? "");
          });
          bottomDialog(nameList, (index) {
            //盲盒不能选择3D
            if (typeList[index].id == 2) {
              EasyLoading.showToast("盲盒不支持${nameList[index]}");
              return;
            }
            setState(() {
              textItem2 = nameList[index];
              typeID = "${typeList[index].id}";
            });
          });
        }
      }),
      firstImg(),
      textFieldViewItem(
          left: "作品标题",
          controller: _controller4,
          focusNode: _nodeText4,
          hintText: "请输入作品专题名称(12个字符以内)"),
      TextViewItem(),
      boxDescribeView(),
      detailsShow(),
      describeView(_controller6, "作品故事"),
    ];
  }

  //item 箭头
  Widget selectTextItem(String title, String content, Color color,
      {VoidCallback? onPressed}) {
    return InkWell(
      onTap: onPressed,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 15),
        height: 61,
        decoration: BoxDecoration(
            border: Border(
          bottom: Divider.createBorderSide(context,
              color: Global.kTheme.colorLine, width: 1),
        )),
        child: Row(
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 14,
                color: Global.kTheme.textPrimary6,
              ),
            ),
            Spacer(),
            Text(
              content,
              style: TextStyle(
                  fontSize: 14,
                  color: color,
                  fontFamily: Global.mySemiboldFont),
            ),
            SizedBox(
              width: 7,
            ),
            if (onPressed != null)
              LoadAssetImage(
                "next_icon",
                width: 7,
                height: 12,
              ),
          ],
        ),
      ),
    );
  }

  //item 选项
  Widget optionViewItem() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15),
      height: 61,
      decoration: BoxDecoration(
          border: Border(
        bottom: Divider.createBorderSide(context,
            color: Global.kTheme.colorLine, width: 1),
      )),
      child: Row(
        children: [
          Text(
            "作品数量",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          Spacer(),
          TextButton(
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                LoadAssetImage(
                  isSingle ? "select_image" : "uncheck_image",
                  width: 16,
                  height: 16,
                ),
                SizedBox(
                  width: 5,
                ),
                Text(
                  "单个作品",
                  style: TextStyle(
                      fontSize: 14,
                      color: Global.kTheme.textPrimary1,
                      fontFamily: Global.mySemiboldFont),
                ),
              ],
            ),
            onPressed: () {
              setState(() {
                isSingle = true;
              });
            },
          ),
          SizedBox(
            width: 40,
          ),
          TextButton(
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                LoadAssetImage(
                  isSingle ? "uncheck_image" : "select_image",
                  width: 16,
                  height: 16,
                ),
                SizedBox(
                  width: 5,
                ),
                Text(
                  "多个作品",
                  style: TextStyle(
                      fontSize: 14,
                      color: Global.kTheme.textPrimary1,
                      fontFamily: Global.mySemiboldFont),
                ),
              ],
            ),
            onPressed: () {
              setState(() {
                isSingle = false;
              });
            },
          ),
        ],
      ),
    );
  }

  //item textField
  Widget textFieldViewItem(
      {required String left,
      required TextEditingController controller,
      required FocusNode focusNode,
      required String hintText,
      TextInputType? keyboardType,
      String? maxNum}) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15),
      height: 61,
      decoration: BoxDecoration(
          border: Border(
        bottom: Divider.createBorderSide(context,
            color: Global.kTheme.colorLine, width: 1),
      )),
      child: Row(
        children: [
          Text(
            left,
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          Expanded(
            child: TextField(
              controller: controller,
              focusNode: focusNode,
              textAlign: TextAlign.end,
              decoration: InputDecoration(
                hintText: hintText,
                border: InputBorder.none, // 去掉下滑线
              ),
              keyboardType: keyboardType,
              onChanged: (value) {
                if (maxNum != null) {
                  if (int.parse(value) > int.parse(maxNum)) {
                    controller.text = maxNum;
                    setState(() {});
                  }
                }
              },
            ),
          ),
        ],
      ),
    );
  }

  //作品数量
  Widget TextViewItem() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15),
      height: 61,
      decoration: BoxDecoration(
          border: Border(
        bottom: Divider.createBorderSide(context,
            color: Global.kTheme.colorLine, width: 1),
      )),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "作品总数",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          Text(
            "$allCount",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
        ],
      ),
    );
  }

  //作品描述
  Widget describeView(TextEditingController controller, String title) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Container(
            height: 140,
            padding: EdgeInsets.symmetric(horizontal: 15, vertical: 0),
            decoration: BoxDecoration(
              color: Color(0xFFF3F3F3),
              borderRadius: BorderRadius.circular(4),
            ),
            child: TextField(
              controller: controller,
              keyboardType: TextInputType.multiline,
              maxLines: null, //不限制行数
              decoration: InputDecoration(
                labelStyle: TextStyle(
                    fontSize: 14,
                    color: Global.kTheme.textPrimary12,
                    fontFamily: Global.mySemiboldFont),
                hintText: "请输入您的作品灵感的由来",
                border: InputBorder.none, // 去掉下滑线
              ),
            ),
          )
        ],
      ),
    );
  }

  //盲盒作品描述
  Widget boxDescribeView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(
                "作品描述",
                style: TextStyle(
                  fontSize: 14,
                  color: Global.kTheme.textPrimary6,
                ),
              ),
              Spacer(),
              Text.rich(TextSpan(children: [
                TextSpan(
                    text: "您可能抽到以下作品中的",
                    style: TextStyle(
                        fontSize: 12,
                        color: Color(0xFFCCCCCC),
                        fontFamily: Global.mySemiboldFont)),
                TextSpan(
                    text: "1",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary4,
                        fontFamily: Global.mySemiboldFont)),
                TextSpan(
                    text: "个",
                    style: TextStyle(
                        fontSize: 12,
                        color: Color(0xFFCCCCCC),
                        fontFamily: Global.mySemiboldFont)),
              ]))
            ],
          ),
          SizedBox(
            height: 5,
          ),
          Builder(builder: (context) {
            double totalHeight = 0;
            if (worksList.length != 0) {
              worksList.forEach((element) {
                totalHeight += 152;
                totalHeight += element.thumb != null ? 90 : 0;
              });
              totalHeight += (worksList.length - 1) * 10;
            }

            return Container(
              height: totalHeight,
              child: ListView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  itemCount: worksList.length,
                  itemBuilder: (context, int index) {
                    return describeItem(index);
                  }),
            );
          }),
          InkWell(
            onTap: () {
              if (worksList.length >= 20) {
                EasyLoading.showToast("最多可以添加20个作品哦~");
                return;
              }
              setState(() {
                worksList.add(WorksBoxModel());
              });
            },
            child: Container(
              height: 53,
              margin: EdgeInsets.only(top: 10),
              decoration: BoxDecoration(
                  color: Color(0xFFF3F3F3),
                  borderRadius: BorderRadius.circular(4)),
              child: Center(
                child: Icon(Icons.add),
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(top: 10),
            child: Text(
              "最多可以添加20个作品哦~",
              style: TextStyle(
                  fontSize: 12,
                  color: Color(0xFFCCCCCC),
                  fontFamily: Global.mySemiboldFont),
            ),
          )
        ],
      ),
    );
  }

  //作品描述Item
  Widget describeItem(int index) {
    WorksBoxModel model = worksList[index];
    return Container(
      height: 152 + (model.thumb != null ? 90 : 0),
      margin: EdgeInsets.only(bottom: 10),
      decoration: BoxDecoration(
        color: Color(0xFFF3F3F3),
        borderRadius: BorderRadius.circular(4),
      ),
      child: Column(
        children: [
          Container(
            height: 50,
            padding: EdgeInsets.symmetric(horizontal: 15),
            child: TextField(
              decoration: InputDecoration(
                labelStyle: TextStyle(
                    fontSize: 14,
                    color: Global.kTheme.textPrimary12,
                    fontFamily: Global.mySemiboldFont),
                hintText: "请输入盲盒作品名称",
                border: InputBorder.none, // 去掉下滑线
              ),
              onChanged: (value) {
                model.title = value;
              },
            ),
          ),
          Container(
            height: 1,
            color: Color(0xFFE7E7E7),
          ),
          Container(
            height: 50,
            padding: EdgeInsets.symmetric(horizontal: 15),
            child: Row(
              children: [
                Expanded(
                  flex: 1,
                  child: TextField(
                    keyboardType:
                        TextInputType.numberWithOptions(decimal: false),
                    inputFormatters: [
                      NumLengthInputFormatter(
                          decimalLength: 0, integerLength: 1000000),
                    ],
                    decoration: InputDecoration(
                      labelStyle: TextStyle(
                          fontSize: 14,
                          color: Global.kTheme.textPrimary12,
                          fontFamily: Global.mySemiboldFont),
                      hintText: "请输入数量",
                      border: InputBorder.none, // 去掉下滑线
                    ),
                    onChanged: (value) {
                      if (value.length == 0) value = "0";
                      model.totalCount = value;
                      allCount = 0;
                      worksList.forEach((element) {
                        allCount += int.parse(element.totalCount ?? "0");
                      });
                      setState(() {});
                    },
                  ),
                ),
                SizedBox(
                  width: 30,
                ),
                Expanded(
                  flex: 1,
                  child: TextField(
                    keyboardType:
                        TextInputType.numberWithOptions(decimal: true),
                    inputFormatters: [
                      NumLengthInputFormatter(
                          decimalLength: 2, integerLength: 1000000),
                    ],
                    decoration: InputDecoration(
                      labelStyle: TextStyle(
                          fontSize: 14,
                          color: Global.kTheme.textPrimary12,
                          fontFamily: Global.mySemiboldFont),
                      hintText: "请输入价值多少钱",
                      border: InputBorder.none, // 去掉下滑线
                    ),
                    onChanged: (value) {
                      model.basePrice = value;
                    },
                  ),
                ),
                Text(
                  "原价(¥)",
                  style: TextStyle(
                      fontSize: 14,
                      color: Global.kTheme.textPrimary4,
                      fontFamily: Global.mySemiboldFont),
                ),
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xFFE7E7E7),
          ),
          InkWell(
            onTap: () {
              _showHintDialog((url) {
                setState(() {
                  model.thumb = url;
                });
              });
            },
            child: Container(
              height: 50 + (model.thumb != null ? 90 : 0),
              child: Center(
                child: model.thumb != null
                    ? ClipRRect(
                        borderRadius: BorderRadius.circular(4),
                        child: Container(
                          width: 137,
                          height: 97,
                          color: Global.kTheme.colorLine,
                          child: Center(
                              child: WrapperImage(
                            url: model.thumb ?? "",
                            width: 137,
                            height: 97,
                          )),
                        ),
                      )
                    : Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          LoadAssetImage(
                            "upload_img",
                            width: 18,
                            height: 18,
                          ),
                          SizedBox(
                            width: 5,
                          ),
                          Text(
                            "上传作品",
                            style: TextStyle(
                                fontSize: 12,
                                color: Global.kTheme.textPrimary4,
                                fontFamily: Global.mySemiboldFont),
                          ),
                        ],
                      ),
              ),
            ),
          )
        ],
      ),
    );
  }

  //上传作品 --图片
  Widget uploadingView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "上传作品",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          SizedBox(
            height: 5,
          ),
          InkWell(
              onTap: () {
                _showHintDialog((url) {
                  setState(() {
                    urlStr1 = url;
                  });
                });
              },
              child: ClipRRect(
                borderRadius: BorderRadius.circular(4),
                child: Container(
                  width: 77,
                  height: 77,
                  color: Global.kTheme.colorLine,
                  child: Center(
                      child: WrapperImage(
                    url: urlStr1,
                    width: 77,
                    height: 77,
                    placeholder: Center(
                      child: LoadAssetImage(
                        "icon_add",
                        width: 25,
                        height: 25,
                      ),
                    ),
                  )),
                ),
              )),
        ],
      ),
    );
  }

  //上传作品 --图片
  Widget uploading3DView() {
    return Container(
        padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
        child: Row(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "上传封面图",
                  style: TextStyle(
                    fontSize: 14,
                    color: Global.kTheme.textPrimary6,
                  ),
                ),
                SizedBox(
                  height: 5,
                ),
                InkWell(
                    onTap: () {
                      _showHintDialog((url) {
                        setState(() {
                          urlStr1 = url;
                        });
                      });
                    },
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(4),
                      child: Container(
                        width: 77,
                        height: 77,
                        color: Global.kTheme.colorLine,
                        child: Center(
                            child: WrapperImage(
                          url: urlStr1,
                          width: 77,
                          height: 77,
                          placeholder: Center(
                            child: LoadAssetImage(
                              "icon_add",
                              width: 25,
                              height: 25,
                            ),
                          ),
                        )),
                      ),
                    )),
              ],
            ),
            SizedBox(
              width: 15,
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "上传3D文件(glb格式文件)",
                  style: TextStyle(
                    fontSize: 14,
                    color: Global.kTheme.textPrimary6,
                  ),
                ),
                SizedBox(
                  height: 5,
                ),
                InkWell(
                    onTap: () {
                      _showHintDialog(
                        (url) {
                          setState(() {
                            urlStr3D = url;
                          });
                        },
                        isFile: true,
                      );
                    },
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(4),
                      child: Container(
                        width: 77,
                        height: 77,
                        color: Global.kTheme.colorLine,
                        child: Center(
                            child: WrapperImage(
                          url: urlStr3D,
                          width: 77,
                          height: 77,
                          placeholder: Center(
                            child: LoadAssetImage(
                              "icon_add",
                              width: 25,
                              height: 25,
                            ),
                          ),
                        )),
                      ),
                    )),
              ],
            ),
          ],
        ));
  }

  //细节展示
  Widget detailsShow() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "细节展示",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            children: [
              InkWell(
                  onTap: () {
                    _showHintDialog((url) {
                      setState(() {
                        urlStr2 = url;
                      });
                    });
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(4),
                    child: Container(
                      width: 77,
                      height: 77,
                      color: Global.kTheme.colorLine,
                      child: Center(
                          child: WrapperImage(
                        url: urlStr2,
                        width: 77,
                        height: 77,
                        placeholder: Center(
                          child: LoadAssetImage(
                            "icon_add",
                            width: 25,
                            height: 25,
                          ),
                        ),
                      )),
                    ),
                  )),
              SizedBox(
                width: 15,
              ),
              Text(
                "例:",
                style: TextStyle(
                    fontSize: 12,
                    color: Color(0xFFCCCCCC),
                    fontFamily: Global.mySemiboldFont),
              ),
              SizedBox(
                width: 5,
              ),
              LoadAssetImage(
                "example_icon",
                width: 47,
                height: 75,
              )
            ],
          ),
          SizedBox(
            height: 8,
          ),
          Text("一张展示作品细节的海报~",
              style: TextStyle(
                  fontSize: 12,
                  color: Color(0xFFCCCCCC),
                  fontFamily: Global.mySemiboldFont)),
        ],
      ),
    );
  }

  //上传首图
  Widget firstImg() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "上传首图",
            style: TextStyle(
              fontSize: 14,
              color: Global.kTheme.textPrimary6,
            ),
          ),
          SizedBox(
            height: 5,
          ),
          InkWell(
              onTap: () {
                _showHintDialog((url) {
                  setState(() {
                    urlStr3 = url;
                  });
                });
              },
              child: ClipRRect(
                borderRadius: BorderRadius.circular(4),
                child: Container(
                  width: 77,
                  height: 77,
                  color: Global.kTheme.colorLine,
                  child: Center(
                      child: WrapperImage(
                    url: urlStr3,
                    width: 77,
                    height: 77,
                    placeholder: Center(
                      child: LoadAssetImage(
                        "icon_add",
                        width: 25,
                        height: 25,
                      ),
                    ),
                  )),
                ),
              )),
          SizedBox(
            height: 8,
          ),
          Text("上传盲盒首图",
              style: TextStyle(
                  fontSize: 12,
                  color: Color(0xFFCCCCCC),
                  fontFamily: Global.mySemiboldFont)),
        ],
      ),
    );
  }

  //底部弹出
  void bottomDialog(List<String> nameList, ValueChanged<int> onTap) {
    showModalBottomSheet<void>(
        context: context,

        /// 禁止拖动关闭
        enableDrag: false,

        /// 使用true则高度不受16分之9的最高限制
        isScrollControlled: true,
        backgroundColor: Colors.transparent,
        builder: (_) => MyEditorWorksBottom(
              listName: nameList,
              onTap: onTap,
            ));
  }

  //弹出
  void _showHintDialog(ValueChanged<String> onTap, {bool isFile = false}) {
    showModalBottomSheet<void>(
      context: Get.context!,

      /// 禁止拖动关闭
      enableDrag: true,

      /// 使用true则高度不受16分之9的最高限制
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      barrierColor: Color(0x80000000),
      builder: (_) => Container(
        color: Colors.transparent,
        height: 190,
        width: 120,
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: SelectedImageUtils(
          isFile: isFile,
          determineBack: (String url) {
            onTap(url);
          },
        ),
      ),
    );
  }
}
